package com.junzhiit.nengji.cms.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.junzhiit.nengji.bo.ShopLocatedBO;
import com.junzhiit.nengji.cms.service.ShopLocatedService;
import com.junzhiit.nengji.cms.web.exception.ShopNotFoundException;
import com.junzhiit.nengji.cms.web.util.ViewObjectUtil;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.cms.web.vo.ShopLocatedVO;
import com.junzhiit.nengji.dao.ShopsLocatedDAO;
import com.junzhiit.nengji.model.ShopsLocated;

@Service
public class ShopLocatedServiceImpl extends BaseServiceImpl implements ShopLocatedService {
	
	@Autowired
	private ShopsLocatedDAO shopsLocatedDAO;
	
	@Override
	public Map<String, Object> findAll(DataTablesParamVO dtp, ShopLocatedVO shopLocatedVO) {
		// TODO Auto-generated method stub
		ShopLocatedBO shopLocatedBO=new ShopLocatedBO();
		BeanUtils.copyProperties(shopLocatedVO,shopLocatedBO);
		
		List<ShopLocatedBO> list = shopsLocatedDAO.findAll(shopLocatedBO,dtp.getStart(), dtp.getLength());
		int totalCount = shopsLocatedDAO.getTotalCount(shopLocatedBO);
		return ViewObjectUtil.dataTables(list, dtp.getDraw(), totalCount);
	}

	@Override
	public ResultVO fingShopsLocatedById(String id) {
		ResultVO result = new ResultVO();
		ShopLocatedBO bo = shopsLocatedDAO.fingShopsLocatedById(id);
		result.setData(bo);
		return result;
	}

	@Override
	public ResultVO updatedById(ShopLocatedVO shopLocatedVO) {
		ResultVO result = new ResultVO();
		ShopsLocated shopLocated = shopsLocatedDAO.query(shopLocatedVO.getShopLocatedID());
		if (shopLocated == null) {
			throw new ShopNotFoundException("找不到入驻信息");
		}
		BeanUtils.copyProperties(shopLocatedVO,shopLocated);
		boolean boo = shopsLocatedDAO.update(shopLocated);
		result.setData(boo);
		return result;
	}

}
